package o;

import android.annotation.TargetApi;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.ConnectivityManager;
import android.net.ConnectivityManager.NetworkCallback;
import android.net.Network;
import android.net.NetworkRequest;
import android.net.NetworkRequest.Builder;
import android.os.Handler;
import android.os.Looper;
import androidx.annotation.RequiresApi;
import com.google.android.exoplayer2.scheduler.Requirements;

public final class ahw {
    private a ˊ;
    private boolean ˋ;
    private final Requirements ˎ;
    private final Context ˏ;
    private final e ॱ;
    private b ॱॱ;

    public interface e {
        void ˊ(ahw o_ahw);

        void ˏ(ahw o_ahw);
    }

    class a extends BroadcastReceiver {
        final /* synthetic */ ahw ˏ;

        private a(ahw o_ahw) {
            this.ˏ = o_ahw;
        }

        public void onReceive(Context context, Intent intent) {
            if (!isInitialStickyBroadcast()) {
                ahw.ˏ(this.ˏ + " received " + intent.getAction());
                this.ˏ.ˎ();
            }
        }
    }

    @RequiresApi(api = 21)
    final class b extends NetworkCallback {
        final /* synthetic */ ahw ॱ;

        private b(ahw o_ahw) {
            this.ॱ = o_ahw;
        }

        public void onAvailable(Network network) {
            super.onAvailable(network);
            ahw.ˏ(this.ॱ + " NetworkCallback.onAvailable");
            this.ॱ.ˎ();
        }

        public void onLost(Network network) {
            super.onLost(network);
            ahw.ˏ(this.ॱ + " NetworkCallback.onLost");
            this.ॱ.ˎ();
        }
    }

    public ahw(Context context, e eVar, Requirements requirements) {
        this.ˎ = requirements;
        this.ॱ = eVar;
        this.ˏ = context.getApplicationContext();
        ˏ(this + " created");
    }

    public void ˋ() {
        amm.ॱ(Looper.myLooper());
        this.ˋ = this.ˎ.ॱ(this.ˏ);
        IntentFilter intentFilter = new IntentFilter();
        if (this.ˎ.ˋ() != 0) {
            if (anr.ˋ >= 23) {
                ˏ();
            } else {
                intentFilter.addAction("android.net.conn.CONNECTIVITY_CHANGE");
            }
        }
        if (this.ˎ.ॱ()) {
            intentFilter.addAction("android.intent.action.ACTION_POWER_CONNECTED");
            intentFilter.addAction("android.intent.action.ACTION_POWER_DISCONNECTED");
        }
        if (this.ˎ.ˊ()) {
            if (anr.ˋ >= 23) {
                intentFilter.addAction("android.os.action.DEVICE_IDLE_MODE_CHANGED");
            } else {
                intentFilter.addAction("android.intent.action.SCREEN_ON");
                intentFilter.addAction("android.intent.action.SCREEN_OFF");
            }
        }
        this.ˊ = new a();
        this.ˏ.registerReceiver(this.ˊ, intentFilter, null, new Handler());
        ˏ(this + " started");
    }

    public void ˊ() {
        this.ˏ.unregisterReceiver(this.ˊ);
        this.ˊ = null;
        if (this.ॱॱ != null) {
            ॱ();
        }
        ˏ(this + " stopped");
    }

    public String toString() {
        return super.toString();
    }

    @TargetApi(23)
    private void ˏ() {
        ConnectivityManager connectivityManager = (ConnectivityManager) this.ˏ.getSystemService("connectivity");
        NetworkRequest build = new Builder().addCapability(16).build();
        this.ॱॱ = new b();
        connectivityManager.registerNetworkCallback(build, this.ॱॱ);
    }

    private void ॱ() {
        if (anr.ˋ >= 21) {
            ((ConnectivityManager) this.ˏ.getSystemService("connectivity")).unregisterNetworkCallback(this.ॱॱ);
            this.ॱॱ = null;
        }
    }

    private void ˎ() {
        boolean ॱ = this.ˎ.ॱ(this.ˏ);
        if (ॱ == this.ˋ) {
            ˏ("requirementsAreMet is still " + ॱ);
            return;
        }
        this.ˋ = ॱ;
        if (ॱ) {
            ˏ("start job");
            this.ॱ.ˏ(this);
            return;
        }
        ˏ("stop job");
        this.ॱ.ˊ(this);
    }

    private static void ˏ(String str) {
    }
}
